%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright (c) 2019 Mahmoud Afifi
% York University, Canada
% Email: mafifi@eecs.yorku.ca - m.3afifi@gmail.com
% Permission is hereby granted, free of charge, to any person obtaining 
% a copy of this software and associated documentation files (the 
% "Software"), to deal in the Software with restriction for its use for 
% research purpose only, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included
% in all copies or substantial portions of the Software.
%
% The Software is provided "as is", without warranty of any kind.
%
% Please cite the following work if this program is used:
% Mahmoud Afifi, Brian Price, Scott Cohen, and Michael S. Brown, Image Recoloring Based on Object Color Distributions, Eurographics 2019 - Short Papers, 2019
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%


function [bestName,best,list]=pickBestCandidate( mask )
%pickBestCandidate function: suggest best cadidate to start with in order
%to get the conditional probability of given image

%this is the ratio of training example for each object in Scene Parsing
%dataset
data_points_ratio=[0.070178,...
0.036591,...
0.049899 ,...
0.056404,...
0.040425,...
0.039844,...
0.024168,...
0.011054,...
0.028384,...
0.014652,...
0.017263,...
0.018541,...
0.030697,...
0.010842,...
0.019837,...
0.025834,...
0.010237,...
0.024198,...
0.013005,...
0.019734,...
0.019147,...
0.004252,...
0.019952,...
0.007214,...
0.008504,...
0.004040,...
0.003937,...
0.007444,...
0.006857,...
0.002901,...
0.007099,...
0.003156,...
0.008389,...
0.004228,...
0.004731,...
0.002290,...
0.018674,...
0.002447,...
0.004864,...
0.008765,...
0.002489,...
0.008704,...
0.004834,...
0.016021,...
0.003325,...
0.002223,...
0.001872,...
0.007153,...
0.001738,...
0.002835,...
0.002429,...
0.000787,...
0.003398,...
0.005324,...
0.000509,...
0.001042,...
0.001199,...
0.005633,...
0.000842,...
0.003416,...
0.001938,...
0.001581,...
0.001666,...
0.002029,...
0.004797,...
0.002393,...
0.007923,...
0.006736,...
0.001611,...
0.003986,...
0.001999,...
0.003216,...
0.002235,...
0.000872,...
0.001605,...
0.001963,...
0.001841,...
0.001030,...
0.000412,...
0.000394,...
0.001496,...
0.002980,...
0.015191,...
0.002665,...
0.000818,...
0.003531,...
0.003222,...
0.012035,...
0.000430,...
0.003743,...
0.000806,...
0.000503,...
0.001078,...
0.006009,...
0.001096,...
0.002726,...
0.000248,...
0.001860,...
0.005845,...
0.000709,...
0.002144,...
0.000654,...
0.003368,...
0.000315,...
0.000600,...
0.000345,...
0.000400,...
0.000466,...
0.002059,...
0.000400,...
0.002817,...
0.000303,...
0.003768,...
0.000485,...
0.000357,...
0.003210,...
0.001708,...
0.000442,...
0.001290,...
0.000824,...
0.000703,...
0.001611,...
0.000351,...
0.002526,...
0.001932,...
0.007214,...
0.000588,...
0.002096,...
0.000315,...
0.001490,...
0.000654,...
0.001217,...
0.001720,...
0.001623,...
0.006178,...
0.007759,...
0.003198,...
0.002738,...
0.004064,...
0.002405,...
0.000557,...
0.001381,...
0.003368,...
0.001314,...
0.001248,...
0.000763,...
0.001078,...
0.003053,...
0.004682,...
0.002550];


objects=setdiff(unique(mask)',0); %extract the 'others' object class, and get all object classes in the input image

scores=zeros(length(objects),1); %scores will be stored here
counter=1;
for obj=objects %for each object, we compute the pixels ratio in the input image
    temp_BW=(mask==obj);
    area_ratio=sum(temp_BW(:))/(size(mask,1)*size(mask,2));
    scores(counter)=(data_points_ratio(obj)+area_ratio)/2; %the score is simply the summation of training samples score and pixel ratio scores. 
    scores(counter)=area_ratio;
    counter=counter+1;
end
[scores,ind]=sort(scores); 
best=objects(ind(end));
bestName=getObjectName(best); %return corresponding object class names
ind=ind(end-1:-1:1);
list=objects(ind);
end

